package com.ss.android.article.base.feature.detail2.widget;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.detail.model.ArticleInfo.RelatedNewsItem;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.j.ClickableBackgroundCompat;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONObject;

public final class RelatedNewsHolder {
    public static final int[] a = new int[]{16, 16, 16, 16};
    long b;
    public int c;
    public boolean d;
    public int e;
    public int f;
    public View root;
    public TextView label;
    public TextView title;
    public ImageView divider;
    public RelatedNewsItem k;
    public Context l;
    public AppData m;
    public final Resources n;
    public long o;
    public final View.OnClickListener p;
    private boolean q;

    public RelatedNewsHolder(Context context) {
        this.q = false;
        this.p = new View.OnClickListener() {

            public final void onClick(View view) {
                String v0_2;
                String v1_1;
                Object v0_1;
                long v4 = 0;
                RelatedNewsHolder v8 = RelatedNewsHolder.this;
                if (view != null) {
                    Object v1 = null;
                    try {
                        v0_1 = view.getTag();
                        if (!(v0_1 instanceof RelatedNewsHolder)) {
                            v0_1 = v1;
                        }
                        if (v0_1 == null) {
                            return;
                        }

                        if (((RelatedNewsHolder) v0_1).k == null) {
                            return;
                        }

                        if (((RelatedNewsHolder) v0_1).k.f <= v4) {
                            return;
                        }

                        v8.b = System.currentTimeMillis();
                        ((RelatedNewsHolder) v0_1).title.setSelected(false);
                        if (v8.b > v4) {
                            ((RelatedNewsHolder) v0_1).title.setTextColor(v8.n.getColor(com.ss.android.article.browser.R.color.bx));
                        }

                        String v2 = "detail";
                        if ((v8.l instanceof com.ss.android.article.base.feature.detail2.h)) {
                            v2 = ((com.ss.android.article.base.feature.detail2.h) v8.l).l();
                        }

                        MobClickCombiner.onEvent(v8.l, v2, "click_related", v8.o, 0);
                        if (android.support.design.a.isTextEmpty(v8.k.e)) {
                            return;
                        }

                        v1_1 = v8.k.e;
                        if (!AppData.getInstance().getAbSettings().isRelatedNewsJumpToTT()) {
                            v0_2 = v1_1;
                        } else if (v1_1.startsWith("snssdk1212")) {
                            v0_2 = v1_1.replaceFirst("snssdk1212", "snssdk143");
                            if (android.support.design.a.a(view.getContext(), new Intent("android.intent.action.VIEW", Uri.parse(v0_2)))) {
                                reportJumpToTT(v0_2, "article");
                            } else {
                                v0_2 = v0_2.replaceFirst("snssdk143", "snssdk35");
                                if (android.support.design.a.a(v8.l, new Intent("android.intent.action.VIEW", Uri.parse(v0_2)))) {
                                    reportJumpToTT(v0_2, "article");
                                } else {
                                    v0_2 = v1_1;
                                }
                            }
                        } else {
                            v0_2 = v1_1;
                        }
                        AppUtil.b(v8.l, v0_2);
                    } catch (Throwable v0) {
                        v0.printStackTrace();
                    }
                }
            }
        };
        this.l = context;
        this.m = AppData.getInstance();
        this.n = context.getResources();
    }

    public final void a() {
        if (this.q != AppData.isNightMode()) {
            this.q = AppData.isNightMode();
            boolean v0 = this.q;
            ClickableBackgroundCompat.setClickableBackground(this.root, v0);
            if (this.b > 0) {
                this.title.setTextColor(this.n.getColor(com.ss.android.article.browser.R.color.bx));
            } else {
                this.title.setTextColor(this.n.getColor(com.ss.android.article.browser.R.color.ssxinzi1));
            }

            if (this.d) {
                this.a(v0);
            } else {
                this.label.setBackgroundDrawable(this.l.getResources().getDrawable(com.ss.android.article.browser.R.drawable.b6));
                this.label.setTextColor(this.l.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi5));
            }

            this.divider.setImageResource(com.ss.android.article.browser.R.color.hh);
        }
    }

    public static void reportJumpToTT(String scheme, String position) {
        try {
            JSONObject jo = new JSONObject();
            jo.put("scheme", scheme);
            jo.put("position", position);
            android.support.design.a.onEvent("jump_to_tt", jo);
        } catch (Exception exception) {
        }
    }

    public final void a(boolean arg4) {
        if (this.d) {
            int v1 = arg4 ? this.e : this.f;
            ((GradientDrawable)this.label.getBackground().mutate()).setStroke(this.c, v1);
            this.label.setTextColor(v1);
        }
    }
}

